<template>
  <div class="m-geo">
    <i class="iconfont icon-lbs"><span>{{ city ? city : '加载中...' }}</span></i>
    <nuxt-link to="/changeCity" class="changeCity">
      切换城市
    </nuxt-link>
  </div>
</template>

<script>
import cookies from 'vue-cookies'
// import { mapActions } from 'vuex'
export default {
  data () {
    return {
      city: ''
    }
  },
  watch: {
    $route () {
      this.city = cookies.get('city') ? cookies.get('city') : this.$store.state.geo.position.city
    }
  },
  mounted () {
    this.city = cookies.get('city') ? cookies.get('city') : this.$store.state.geo.position.city
    // if (!location.href.includes('=')) {
    //   this.getCity()
    // }
  },
  methods: {
    // ...mapActions('geo', ['setPosition']),
    // getCity () {
    //   if (cookies.get('city') !== this.$store.state.geo.position.city) {
    //     this.$confirm(`当前城市定位在${this.$store.state.geo.position.city}, 是否切换为当前城市?`, '提示', {
    //       confirmButtonText: '确定',
    //       cancelButtonText: '取消',
    //       type: 'warning'
    //     }).then(() => {
    //       cookies.remove('city')
    //       this.city = this.$store.state.geo.position.city
    //       // 修改vuex中的城市定位
    //       this.setPosition({
    //         province: this.$store.state.geo.position.province,
    //         city: this.city
    //       })
    //       cookies.set('city', this.city)
    //       this.$message({
    //         type: 'success',
    //         message: '切换成功!'
    //       })
    //       location.reload()
    //     }).catch(() => {
    //       this.city = cookies.get('city')
    //       this.$message({
    //         type: 'info',
    //         message: '已取消切换'
    //       })
    //     })
    //   }
    // }
  }
}
</script>

<style></style>
